package com.aptech.action;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.aptech.dao.UserOperateDao;
import com.aptech.model.Userprofile;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class UserOperate extends ActionSupport {
	//通过对象获得页面属性值
	private Userprofile user;
	
	
	//查询用户信息
	public String selectUser(){
		//获取Session里面的用户姓名
		ActionContext context = ActionContext.getContext();
		String name=context.getSession().get("isLogin").toString();
		
		//调用UserProfileDao层方法，根据用户名查询用户相关信息
		UserOperateDao userdao=new UserOperateDao();
		Userprofile user1=userdao.selectUser(name);
		
		//将返回的user1对象里的属性值塞入request(context);
		HttpServletRequest request=ServletActionContext.getRequest();
		request.setAttribute("userName",user1.getUsername());
		request.setAttribute("age",user1.getAge());
		request.setAttribute("sex",user1.getSex());
		request.setAttribute("phone",user1.getPhone());
		request.setAttribute("address",user1.getAddress());
		
		return SUCCESS;
	}
	
	
	//添加用户
	public String insertUser(){
		return null;
	}
	
	//删除用户
	public String deleteUser(){
		return null;
	}

	public Userprofile getUser() {
		return user;
	}

	public void setUser(Userprofile user) {
		this.user = user;
	}
	

}
